package com.lu.spzx.service.handler;

import com.lu.spzx.model.vo.common.Result;
import com.lu.spzx.service.exception.GuiguException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    // 处理自定义异常
    @ExceptionHandler(value = GuiguException.class)
    public Result error(GuiguException exception) {
        exception.printStackTrace();
        return Result.build(null, exception.getResultCodeEnum());
    }

    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.build(null, 201, e.getMessage());
    }

}
